﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TWS.Cart.Business;
using TWS.Cart.Data;

public partial class Application_Cart_Administration_OrderDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack)
		{
			ViewCartOrderDetailCollection orderDetail = new ViewCartOrderDetailCollection()
				.Where(ViewCartOrderDetail.Columns.OrdersId,Request.QueryString["Id"])
				.Load();

			GridViewOrderDetail.DataSource = orderDetail;
			GridViewOrderDetail.DataBind();
		}
    }

	int TotalItems = 0;
	decimal TotalSalesPrice = 0;

	protected void Grid_OnRowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			ViewCartOrderDetail od = (ViewCartOrderDetail)e.Row.DataItem;

			TotalItems += od.Quantity;
			TotalSalesPrice += od.SalePrice;
		}
		else if (e.Row.RowType == DataControlRowType.Footer)
		{
			e.Row.Cells[2].Text = "Totals:";
			e.Row.Cells[3].Text = TotalItems.ToString();
			e.Row.Cells[4].Text = String.Format("{0:c}",TotalSalesPrice);
		}
	}
}
